package company.tx1;

import java.util.Scanner;

public class Tx5 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();
        char[] chars = s.toCharArray();
        int[] array = new int[n * 2];
        for (int i = 0; i < n * 2; i++) {
            array[i] = sc.nextInt();
        }
        boolean flag = true;
        int count = 0;
        int left = 0, right = n * n - 1;
        while (flag) {
            flag = false;
            if (array[left] > array[right] && chars[left] == chars[right]) {
                swap(chars, array, left, right);
                count++;
                flag = true;
                left++;
                right--;
            }
        }
        System.out.println(count);
    }

    private static void swap(char[] chars, int[] array, int i, int j) {
        char tmpChar = chars[i];
        chars[i] = chars[j];
        chars[j] = tmpChar;

        int tmpNum = array[i];
        array[i] = array[j];
        array[j] = tmpNum;
    }
}
